<template>
	<view class="container">
		<!-- 搜索栏 -->
		<view class="card flex justify-between mb-20">
			<view class="flex align-center" style="width: 80%;">
				<text class="iconfont icon-search" style="margin-right: 10rpx;"></text>
				<input type="text" placeholder="搜索景点门票" style="flex: 1;" />
			</view>
			<view class="text-primary">搜索</view>
		</view>
		
		<!-- 分类筛选 -->
		<view class="card mb-20">
			<scroll-view scroll-x class="scroll-x">
				<view class="flex">
					<view class="category-item" :class="{active: activeCategory === index}" v-for="(item, index) in categoryList" :key="index" @click="switchCategory(index)">
						{{ item }}
					</view>
				</view>
			</scroll-view>
		</view>
		
		<!-- 门票列表 -->
		<view class="ticket-list">
			<view class="card mb-20" v-for="(item, index) in ticketList" :key="index" @click="goToDetail(item)">
				<view class="flex">
					<image :src="item.image" mode="aspectFill" style="width: 200rpx; height: 150rpx; border-radius: 10rpx;"></image>
					<view style="flex: 1; margin-left: 20rpx;">
						<text class="block" style="font-weight: bold; font-size: 32rpx;">{{ item.title }}</text>
						<text class="block text-gray mt-10">{{ item.tag }}</text>
						<view class="flex justify-between mt-20">
							<text class="text-red" style="font-size: 36rpx;">¥{{ item.price }}</text>
							<text class="button" style="padding: 10rpx 20rpx; font-size: 24rpx;">立即购买</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				activeCategory: 0,
				categoryList: ['全部', '景区', '乐园', '展览', '演出', '温泉'],
				ticketList: [
					{
						id: 1,
						title: '故宫博物院门票',
						tag: '文化古迹 | 5A景区',
						price: 60,
						image: '/static/gugong.jpg'
					},
					{
						id: 2,
						title: '颐和园门票',
						tag: '皇家园林 | 5A景区',
						price: 30,
						image: '/static/yiheyuan.jpg'
					},
					{
						id: 3,
						title: '北京环球影城一日票',
						tag: '主题乐园 | 限时特惠',
						price: 528,
						image: '/static/huanqiu.jpg'
					},
					{
						id: 4,
						title: '八达岭长城门票',
						tag: '世界文化遗产 | 5A景区',
						price: 40,
						image: '/static/changcheng.jpg'
					}
				]
			}
		},
		methods: {
			switchCategory(index) {
				this.activeCategory = index;
			},
			goToDetail(item) {
				uni.navigateTo({
					url: '/pages/ticket/detail?id=' + item.id
				})
			}
		}
	}
</script>

<style>
	.scroll-x {
		white-space: nowrap;
		width: 100%;
	}
	
	.category-item {
		display: inline-block;
		padding: 15rpx 30rpx;
		margin-right: 20rpx;
		border-radius: 30rpx;
		background: #f5f5f5;
	}
	
	.category-item.active {
		background: #4caf50;
		color: #fff;
	}
</style>